<template>
  <div class="container-fuild">
    <div class="row page-titles">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">实训班 /</li>
        <li class="breadcrumb-item">学生评教</li>
      </ol>
    </div>
    <div class="row">
      <div class="card">
        <div class="card-header">
          <p class="card-title">教学质量评价</p>
        </div>
        <div class="card-body custom-ekeditor">
          <div id="ckeditor">
            <el-table
                :data="tableList1" :cell-style="cellStyle"
                style="width: 100%">
              <el-table-column
                  label="实训班"
                  width="230">
                <template slot-scope="scope">
                  <span>{{ scope.row.className }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="开始日期"
                  width="120">
                <template slot-scope="scope">
                  <span>{{ scope.row.startTime }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="结束日期"
                  width="120">
                <template slot-scope="scope">
                  <span>{{ scope.row.endTime }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="期数"
                  width="120">
                <template slot-scope="scope">
                  <span>{{ scope.row.period }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="实训教师"
                  width="100">
                <template slot-scope="scope">
                  <span>{{ scope.row.teacherName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="评价状态" width="120">
                <template slot-scope="scope">
                  <span>{{ scope.row.trainingStudent.commentStatus }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button size="mini" style="background-color: steelblue ;color: white"
                             @click="tableShow(scope.$index, scope.row)">去评价
                  </el-button>
                  <el-dialog title="教学质量评价" :visible.sync="dialogVisible"
                             append-to-body width="60%" class="showAll_dialog">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" :inline="true">
                      <el-row>
                        <el-form-item label="实训科目">
                          <el-input v-model="form.className" :disabled="isInput"></el-input>
                        </el-form-item>
                        <el-form-item label="实训期数">
                          <el-input v-model="form.period" :disabled="isInput"></el-input>
                        </el-form-item>
                      </el-row>
                      <el-row>
                        <el-form-item label="实训教师">
                          <el-input v-model="form.teacherName" :disabled="isInput"></el-input>
                        </el-form-item>
                        <el-form-item label="实训单位">
                          <el-input v-model="form.company" :disabled="isInput"></el-input>
                        </el-form-item>
                      </el-row>
                      <el-row>
                        <el-form-item prop="desc1" style="padding-left: 13px">
                          <p style="font-size: 15px">对实训单位的总体评价:</p>
                          <el-input placeholder="评价不少于50字" style="width: 570px" type="textarea"
                                    v-model="ruleForm.desc1"></el-input>
                        </el-form-item>
                      </el-row>
                      <el-row>
                        <el-form-item prop="desc2" style="padding-left: 13px;">
                          <p style="font-size: 15px">对院系实习/实训工作有何意见和建议:</p>
                          <el-input style="width: 570px" type="textarea" v-model="ruleForm.desc2"></el-input>
                        </el-form-item>
                      </el-row>

                      <!--                      <el-form-item >-->
                      <!--                        <el-button type="primary" @click="onSubmit">立即创建</el-button>-->
                      <!--                        <el-button>取消</el-button>-->
                      <!--                      </el-form-item>-->
                    </el-form>

                    <span slot="footer" class="dialog-footer">
<!--                      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>-->
                      <el-button type="primary" @click="submitForm('ruleForm')"
                                 style="background-color: #016bb7">
                        立即创建
                      </el-button>
                      <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </span>
                  </el-dialog>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  data() {
    return {
      id:this.$route.query.id,
      isInput: true,
      form: {
        company: '',
        className: '',
        period: '',
        teacherName: '',
      },
      rules: {
        desc1: [
          {required: true, message: '请填写评价', trigger: 'blur'},
          {min: 50, max: 300, message: '请输入 50 - 300 个字', trigger: 'blur'}
        ],
        desc2: [
          {required: true, message: '请填写评价', trigger: 'blur'}
        ]
      },
      dialogVisible: false,
      tableList1: [{
        classname: "2019级软件工程JavaEE实训"
      }],
      ruleForm: {
        desc1: '',
        desc2: '',
      },
      className: '',
      CommentStatus: '',

    }
  },
  mounted() {
    this.classShow();
  },
  methods: {
    tableShow(index, row) {  //显示教评表单
      if(row.trainingStudent.commentStatus==='已评价'){
        alert('您已经评价过了！');
      }
      else {
        this.dialogVisible = true;
        this.className = row.className;
        this.CommentStatus = row.trainingStudent.commentStatus;
        let that = this;
        this.axios.get("http://localhost:9090/user/getProject/" + this.className +'/'+ this.id).then(function (ret) {
          // console.log(ret.data.data)
          that.form.company = ret.data.data[0].company;
          that.form.teacherName = ret.data.data[0].teacherName;
          that.form.period = ret.data.data[0].period;
          that.form.className = ret.data.data[0].className;
          // console.log(ret.data.data[0].id)
        }).catch(function (err) {
        })
      }

    },
    classShow: function () {  //显示默认的学生课程页面
      let that = this;
      this.axios.get('http://localhost:9090/user/getTrainClass/'+that.id).then(function (ret) {
        // console.log(ret);
        that.tableList1 = ret.data.data;
        // that.commentStatus = ret.data.data.trainingStudent.CommentStatus;
        // console.log(ret.data.data.trainingStudent.CommentStatus);
      }).catch(function (err) {
      })
    },
    cellStyle({row, columnIndex}) {  //设置“未评价”为红色字体
      if (columnIndex === 5 && row.trainingStudent.commentStatus === "未评价") { //指定坐标rowIndex ：行，columnIndex ：列
        return 'color:red' //rgb(105,0,7)
      } else {
        return 'color:#7d94c0';
      }
    },
    submitForm(formName) {
      let that1 = this;
      let that2 = this;
      let data = this.form;
      that1.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.CommentStatus === '已评价'){
            alert('您已经评价过了！')
          }
          else{
            this.$axios.post('http://localhost:9090/addComment', {
              className: that2.form.className,
              studentId: that2.id,
              content: that2.ruleForm.desc1,
              device: that2.ruleForm.desc2,
            }).then(res => {
              // console.log(data)
              // console.log(res)
              alert('提交成功!');
            }).catch(error => {
              console.log('请求失败')
              // console.log(error)
            })
          }



          // that1.$axios({
          //   method:'post',
          //   url:'http://localhost:9090/addComment',
          //   header:{
          //     'Content-type':'application/json'
          //   },
          //   data:{
          //     className:this.form.className,
          //     studentId:'201941404202',
          //     content:this.ruleForm.desc1,
          //     device:this.ruleForm.desc2,
          //   },
          //   transformRequest:[function (data){
          //     let ret =''
          //     for (let it in data){
          //       ret +=encodeURIComponent(it) + '=' +encodeURIComponent(data[it]) + '&'
          //     }
          //     return ret
          //   }]
          // }).then((res) => {
          //   console.log(res.data)
          // }).catch(function (error) {
          //     console.log('请求失败：' + error)
          //   })

          // that.axios.post(url, {classname:'yyy',class:'zzz'},
          //     {
          //       transformRequest: [function (data) {
          //         // Do whatever you want to transform the data
          //         let ret = ''
          //         for (let it in data) {
          //           ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
          //         }
          //         return ret
          //       }]
          //     }
          // )
          //     .then(value => {
          //   console.log('value=' + value);  //设置响应
          //   // document.getElementById("result").innerHTML = value.data;
          // }).catch(function (err) {
          //   console.log('请求失败：' + err.status + ',' + err.statusText)
          // })

          this.dialogVisible = false;
          this.$router.go(0);
        } else {
          console.log('error submit!!');
          return false;
        }
      })
      ;
    }
    ,
    resetForm(formName) {  //重置
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>
/*表头*/
.container-fuild {
  float: left;
  /*padding-top:1.875rem;*/
  padding-right: 1.875rem;
  padding-left: 1.875rem;
  width: 93%;
  margin-right: auto;
  margin-left: auto;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  color: #7d94c0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.page-titles {
  justify-content: space-between;
  /*padding: 0.1375rem 0.5rem;*/
  padding-top: 0.25rem;
  padding-right: 1.875rem;
  padding-bottom: 0.25rem;
  padding-left: 1.875rem;
  background: #fff;
  margin-bottom: 1.875rem;
  border-radius: 1rem;
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
}

.page-titles .breadcrumb {
  padding: 0;
  background: transparent;
  font-size: 1.1875rem;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  list-style: none;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
}

.breadcrumb li.active {
  font-weight: 600;
  font-size: 1.1875rem;
}

.breadcrumb li {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 0.5rem;
  font-size: 1.1875rem;
}

/*主题部分*/
.row {
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
  margin-top: calc(var(--bs-gutter-y) * -1);
  margin-right: calc(var(--bs-gutter-x) / -2);
  margin-left: calc(var(--bs-gutter-x) / -2);
}

.card {
  width: 100%;
  margin-bottom: 1.875rem;
  background-color: #fff;
  transition: all .5s ease-in-out;
  position: relative;
  /*border: 0rem solid transparent;*/
  border-radius: 1.25rem;
  /*box-shadow: 0rem 0.3125rem 0.3125rem 0rem rgb(82 63 105 / 5%);*/
  height: calc(100% - 30px);

  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-clip: border-box;
}

.card-header {
  border-color: #f5f5f5;
  position: relative;
  background: transparent;
  /*padding-top: 0rem;*/
  padding-right: 1.875rem;
  /*padding-bottom: 0rem;*/
  padding-left: 1.875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  font-size: 1.1rem;
  font-weight: 300;
  color: #909399;
  text-transform: capitalize;
}

.card-body {
  padding-top: 0.125rem;
  padding-right: 1.875rem;
  padding-bottom: 1.125rem;
  padding-left: 1.875rem;

  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: auto;
}


/*弹窗*/
/*.el-table  {*/
/*  background: oldlace;*/
/*}*/

/*.el-table {*/
/*  background: #f0f9eb;*/
/*}*/

/*让dialog能够悬浮在中间*/
.showAll_dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
}

::v-deep .el-dialog {
  margin: 0 auto !important;
  height: 80%;
  overflow: auto;
  background-color: white;
}

.el-dialog__body {
  position: absolute;
  left: 0;
  top: 54px;
  bottom: 0;
  right: 0;
  z-index: 1;
  overflow: hidden;
  overflow-y: auto;

  line-height: 30px;
  padding: 15px;
}

::v-deep .el-button{
  border-radius: 5px;
}
</style>